package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.vo.DishDto;
import com.itheima.reggie.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;

    //根据分类id查询该分类下所有菜品合集
    @GetMapping("/list")
    public R getDishByCategoryId(Long categoryId){
        return dishService.getDishByCategoryId(categoryId);
    }

    //启用停用
    @PostMapping("/status/{status}")
    public R statusDishUpdate(@PathVariable Integer status, @RequestParam("ids") List<Long> ids) {
        return dishService.updateDishStatus(status, ids);
    }

    //删除菜品
    @DeleteMapping
    public R deleteDish(@RequestParam("ids") List<Long> ids) {
        return dishService.deleteDish(ids);
    }

    //修改菜品
    @PutMapping
    public R updateDish(@RequestBody DishDto dishDto) {
        return dishService.updateDish(dishDto);
    }

    @GetMapping("/{id}")
    public R selectDishById(@PathVariable Long id) {
        return dishService.selectDishById(id);
    }

    @GetMapping("/page")
    //分页查询菜品数据
    public R dishPage(Integer page, Integer pageSize, String name) {
        return dishService.dishPage(page, pageSize, name);
    }

    //新增菜品
    @PostMapping
    public R saveDish(@RequestBody DishDto dishDto) {
        return dishService.saveDish(dishDto);
    }

}
